// ==UserScript==
// @name         交易猫刷新
// @namespace    http://xiaoyou.run/
// @version      0.1
// @description  用于交易猫自抽号刷新使用
// @author       XiaoYou
// @require      https://image.jiaoyimao.com/public/pc/js/dev/lib/jquery-1.10.2.js?2020011613
// @match        https://www.jiaoyimao.com/merchant/giftBag/index
// @grant        none

// ==/UserScript===
(function() {
    'use strict';
    console.log("检测到页面，在商家管理后台页面");
    var productIds=[];
    //页面加载完成
    $(document).ready(function(){
        initUI();
    })

    function initUI() {
        //引入bootstrap2的css
        //https://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css
        var link = document.createElement("link");
        link.rel = "stylesheet";
        link.type = "text/css";
        link.href = "https://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css";
        //自定义样式，取消bootstrap2的一部分样式
        var style = document.createElement("style");
        style.type = "text/css";
        var text = document.createTextNode(".sidebar ul{margin: 0px;} .select-form label{display:inline}"); /* 这里编写css代码 */
        style.appendChild(text);
        //加入head
        var head = document.getElementsByTagName("head")[0];
        head.appendChild(link);
        head.appendChild(style);
      
            console.log($("#game-search-btn"))
        
        //添加设置按钮
        $(".add-new").append('<button type="button" id="btnSetting" class="btn btn-primary">刷新设置</button>')
    }

    function refshProducts(){
        $("#game-search-btn").trigger("click")
    }

    function getAllProducts(){
        $(".btn-gift-stock[data-status='1']").each(
            function(index,item)
            {
                productIds.push($(item).attr("data-id"))
            });
    }

    function offSoldGiftBagGoods(id){
        $.ajax({
            url:"https://www.jiaoyimao.com/merchant/ajax/admin/GiftBagAjax/offSoldGiftBagGoods",
            method:"POST",
            async: true,
            beforeSend: function(request) {
                request.setRequestHeader("actk",$.cookie("actks"));
            },
            data:{
                goodsId:id
            },
            success:function(data){
                console.log(data)
            }
        })
    }

    function getCountWaitDeliver(){
        $.ajax({
            url:"https://www.jiaoyimao.com/merchant/ajax/admin/adminIndexAjax/getCountWaitDeliver",
            async: true,
            beforeSend: function(request) {
                request.setRequestHeader("actk",$.cookie("actks"));
            },
        })
    }

})();